<template>
	<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;line-height: 28px;padding-top: 30px;">
		<text >请访问夜读书网站发布读后感：</text>
		<text user-select="true" style="color: blue;">www.yedushu.com</text>
	</view>
	<!-- <view class="content" v-if="false">
		<view class="fabubutton">
			<text class="fabu"  @click="fabu">确定</text>
		</view>
		<view class="title">
			<textarea v-model="title" class="duhougantitle" auto-height="true" maxlength=100 placeholder="请输入标题" placeholder-class="placeholder"/>
		</view>
		<view class="duhougan">
			<textarea v-model="duhougan" class="duhouganneirong" auto-height="true" maxlength=1000 placeholder="内容..." placeholder-class="placeholder"/>
		</view>
	</view>	 -->
</template>

<script>
	export default {
		data() {
			return {
				uid: '',
				bookid: '',
				title: '', // 读后感标题
				duhougan: '', // 读后感
				rating: 5,
				device: '', // 设备
			}
		},
		onLoad(option) {
			// 获得书籍bookid
			this.bookid = option.bookid;
			
			const userinfo = uni.getStorageSync('userinfo');
			// console.log(JSON.stringify(userinfo));
			this.uid = userinfo.uid;
			
			// 获得设备
			var _this = this;
			uni.getSystemInfo({
			    success: function (res) {
			        // console.log(res.model);
					_this.device = res.model;
			    }
			});
		},
		methods: {
			fabu() {
				if(this.title == '')
				{
					// 没有输入标题
					uni.showToast({
					    title: '标题不能为空',
						icon: 'none',
					    duration: 2000
					});
					
					return;
				}
				
				if(this.duhougan == '')
				{
					// 没有输入读后感内容
					uni.showToast({
					    title: '内容不能为空',
						icon: 'none',
					    duration: 2000
					});
					
					return;
				}
				
				uni.request({
					url: 'https://www.yedushu.cn/api/saveduhougan', // 保存读后感内容
					data: {
						bookid: this.bookid,
						uid: this.uid,
						title: this.title,
						duhougan: this.duhougan,
						rating: this.rating,
						device: this.device,
					},
					method: 'POST',
					success: (res) => {
						if(res.data == 1)
						{
							console.log('保存成功');
						} else {
							console.log('error');
						}
						// 获得书摘列表，触发书籍详情页上的事件，更新长书评列表
						uni.request({
						    url: 'https://www.yedushu.cn/api/bookchangshupinglist/'+ this.bookid, // 长书评列表
						    success: (res) => {
						        // console.log(JSON.stringify(res.data));
								const changpinglists = res.data.data;
								// 触发书籍详情页上的事件，更新长书评（读后感）列表
								uni.$emit("changpinglists",{
										changpinglists: changpinglists,
									},
								);
						    }
						});							
						
						// 书评内容提交成功，跳转到上一页面
						uni.navigateBack({
						    delta: 1
						});
					}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
	}	
	.fabubutton {
		padding: 10px 0;
		width: 100%;
		position: fixed;
		z-index: 100;
		background-color: #FFFFFF;
		display: flex;
		justify-content: flex-end;
	}
	.fabubutton .fabu {
		background-color: #f2f2f2;
		margin: 0px 10px;
		padding: 6px 10px;
		border-radius: 5px;
		text-align: center;
		font-size: 15px;
	}
	.title {
		padding-top: 55px;
		padding-left: 15px;
		padding-right: 15px;
	}
	.duhougantitle {
		width: 100%;
		font-size: 16px;
		font-weight: 600;
		border-bottom: #f1f1f1 1px solid;
		padding: 10px 0;
	}
	.duhougan {
		padding: 10px 15px;
	}
	.duhouganneirong {
		width: 100%;
		font-size: 16px;
		line-height: 28px;
	}	
</style>
